package com.yanqu.road.server.manger.activity.cookboy;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.cookboy.CookBoyConfig;
import com.yanqu.road.entity.activity.cookboy.CookBoyFinishFood;
import com.yanqu.road.entity.activity.cookboy.CookBoyFoodConfig;
import com.yanqu.road.entity.activity.cookboy.process2.CookBoy2DishConfig;
import com.yanqu.road.entity.activity.cookboy.process2.CookBoy2Spoon;
import com.yanqu.road.entity.activity.cookboy.process3.CookBoy3OpenItem;
import com.yanqu.road.entity.enums.activity.eActivityCookBoyType;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.pb.cookboyactivity.CookBoyActivityProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.cookboy.CookBoyActivityModule;
import com.yanqu.road.server.gameplayer.module.cookboy.CookBoyModule;
import com.yanqu.road.server.logic.activity.relation.RelationActivityData;
import com.yanqu.road.server.manger.activity.RelationActivityMgr;
import com.yanqu.road.server.manger.activity.RelationActivityRankMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.pb.CookBoyActivityPb;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class CookBoyActivityMgr extends RelationActivityMgr {

    //小当家第一阶段
    public static final String COOKBOY_ENERGY_PARAM = "30;30";
    public static final String COOKBOY_ENERGY_CD_TIME = "10";
    public static final String COOKBOY_RESTORE_ITEM_ID = "120461";//恢复体力道具id
    public static final String COOKBOY_EXCHANGE_ITEM_ID = "101967";//兑换商店积分道具ID
    public static final String COOKBOY_INGREDIENTS_GENERATE_WEIGHT = "60|20|20|10|10|5";
    public static final String COOKBOY_INGREDIENTS_GENERATE_SCORE = "10|20|30|40|50|60";
    public static final String COOKBOY_INGREDIENTS_COMB_LIST = "2|4|6|8";
    public static final String COOKBOY_INGREDIENTS_COMB_EFFECT_LIST = "1100;1300;1500;1750|1100;1300;1500;1750|1100;1300;1500;1750|1100;1300;1500;1750|1100;1300;1500;1750|1100;1300;1500;1750";
    public static final String COOKBOY_SERVE_FOOD_DAY_START = "10";//每天开始比赛时间小时
    public static final String COOKBOY_SERVE_FOOD_DAY_END = "22";//每天结束比赛时间小时
    public static final String COOKBOY_WORSHIP_REWARDS = "101000=200";//膜拜奖励列表
    public static final String COOKBOY_PARTICPATE_COOKING_MAX_NUM = "50";//总共可以上多少菜
    public static final String COOKBOY_TO_COOKBOY2_RANK = "10";//阶段1晋级阶段2排名

    //小当家第二阶段
    public static final String COOKBOY2_SWITCH = "1";//是否开启凭证参与
    public static final String COOKBOY2_CERTIFICATE_CONSUME = "120466=1";//参与活动需要消耗的凭证道具
    public static final String COOKBOY2_EXCHANGE_ITEM_ID = "101968";//兑换商店积分道具ID
    public static final String COOKBOY2_RESTORE_ITEM_ID = "120462";//恢复体力道具ID，恢复值在道具参数1中
    public static final String COOKBOY2_ENERGY_PARAM = "30;30";//初始体力，体力上限
    public static final String COOKBOY2_ENERGY_CD_TIME = "10";//体力恢复一点时间(秒)
    public static final String COOKBOY2_PICK_DISH_REWARDS = "110000=1;20|110001=1;30";//挑菜随机奖励列表,道具=道具数量;权重
    public static final String COOKBOY2_TRY_DISH_CONFIG = "120463=1;100;100|120464=1;200;200|120465=1;300;300";//赴宴试吃消耗道具和数量;试吃获得积分;开宴获得积分
    public static final String COOKBOY2_WORSHIP_REWARDS = "101000=200";//膜拜奖励列表
    public static final String COOKBOY2_PARTICPATE_COOKING_TIME = "60";//试吃单场时长(分)
    public static final String COOKBOY2_PARTICPATE_COOKING_TABLE = "2";//试吃每人可以开启多少道菜
    public static final String COOKBOY2_SERVE_FOOD_DAY_START = "10";
    public static final String COOKBOY2_SERVE_FOOD_DAY_END = "22";
    public static final String COOKBOY2_HORSE_RACE_LAMP_QUALITY = "4;3";//跑马灯菜品品质(;号隔开)
    public static final String COOKBOY2_ROBOT_ADD = "1000";//机器人填补座位加成积分千分比
    public static final String COOKBOY2_TO_COOKBOY3_BANK = "10";//阶段2晋级阶段3排名
    public static final String COOKBOY2_PICK_UP_ITEMID = "120462";//挑菜使用的道具



    //小当家第三阶段
    public static final String COOKBOY3_SWITCH	 =  "1"; //是否开启凭证参与
    public static final String COOKBOY3_CERTIFICATE_CONSUME	="120467=1";//参与活动需要消耗的凭证道具
    public static final String COOKBOY3_EXCHANGE_ITEM_ID	="101969";//兑换商店积分道具ID
    public static final String COOKBOY3_BANQUET_OPEN_CONFIG	="120468=1;50;60;20|120469=1;100;120;25|120470=1;150;180;30";//开宴道具消耗、试吃人数、持续时间(分)、赴宴人赴宴给开宴人增加的积分
    public static final String COOKBOY3_JOIN_BANQUET_REWARD	="121068=1|121069=1|121070=1";//赴宴奖励宝箱ID，区分不同宴会
    public static final String COOKBOY3_JOIN_BANQUET_SCORE	="100";//赴宴试吃增加的宴会积分
    public static final String COOKBOY3_SERVE_FOOD_DAY_START	="10";//每天开始比赛时间小时
    public static final String COOKBOY3_SERVE_FOOD_DAY_END	="22";//每天结束比赛时间小时
    public static final String COOKBOY3_WORSHIP_REWARDS	="101000=200";//膜拜奖励列表
    public static final String COOKBOY3_ROBOT_ADD = "1000";//机器人填补座位加成积分千分比




    private static Logger logger = LogManager.getLogger(CookBoyActivityMgr.class.getName());

    private static Map<Integer, Map<String, CookBoyConfig>> cookBoyConfigMap = new ConcurrentHashMap<>();

    //活动id 解锁顺序123456
    private static Map<Integer, Map<Integer, CookBoyFoodConfig>> cookBoyFoodConfigMap = new ConcurrentHashMap<>();

    //活动id 挑菜id
    private static Map<Integer, Map<Integer, CookBoy2DishConfig>> cookBoyDishConfigMap = new ConcurrentHashMap<>();

    public static void addChildEvent(List<ActivityInfo> activityInfoList){
        for(ActivityInfo activityInfo : activityInfoList){
            if(activityInfo.getChildType() == eActivityCookBoyType.Process1.getChildType()){
                Map<Integer,Map<Integer,Integer>> eventTypeMap = new ConcurrentHashMap<>();
                Map<Integer,Integer> tempEventMap = new ConcurrentHashMap<>();
                tempEventMap.put(RelationActivityMgr.EVENT_RANK_USER_TYPE, eGamePlayerEventType.CookBoy1IntegralUserCrossRank.getValue());
                tempEventMap.put(RelationActivityMgr.EVENT_RANK_UNION_TYPE, eGamePlayerEventType.CookBoy1IntegralUnionCrossRank.getValue());
                eventTypeMap.put(eGamePlayerEventType.CookBoy1IntegralUserCrossRank.getValue(),tempEventMap);
                addEventRelationMap(activityInfo.getActivityId(),eventTypeMap);

                Map<Integer,Integer> tempRankMap = new ConcurrentHashMap<>();
                tempRankMap.put(RelationActivityMgr.EVENT_RANK_USER_TYPE, eGamePlayerEventType.CookBoy1IntegralUserCrossRank.getValue());
                tempRankMap.put(RelationActivityMgr.EVENT_RANK_UNION_TYPE, eGamePlayerEventType.CookBoy1IntegralUnionCrossRank.getValue());
                addRankEventMap(activityInfo.getActivityId(),tempRankMap);
            }
            if(activityInfo.getChildType() == eActivityCookBoyType.Process2.getChildType()){
                Map<Integer,Map<Integer,Integer>> eventTypeMap = new ConcurrentHashMap<>();
                Map<Integer,Integer> tempEventMap = new ConcurrentHashMap<>();
                tempEventMap.put(RelationActivityMgr.EVENT_RANK_USER_TYPE, eGamePlayerEventType.CookBoy2IntegralUserCrossRank.getValue());
                eventTypeMap.put(eGamePlayerEventType.CookBoy2IntegralUserCrossRank.getValue(),tempEventMap);
                addEventRelationMap(activityInfo.getActivityId(),eventTypeMap);

                Map<Integer,Integer> tempRankMap = new ConcurrentHashMap<>();
                tempRankMap.put(RelationActivityMgr.EVENT_RANK_USER_TYPE, eGamePlayerEventType.CookBoy2IntegralUserCrossRank.getValue());
                addRankEventMap(activityInfo.getActivityId(),tempRankMap);
            }
            if(activityInfo.getChildType() == eActivityCookBoyType.Process3.getChildType()){
                Map<Integer,Map<Integer,Integer>> eventTypeMap = new ConcurrentHashMap<>();
                Map<Integer,Integer> tempEventMap = new ConcurrentHashMap<>();
                tempEventMap.put(RelationActivityMgr.EVENT_RANK_USER_TYPE, eGamePlayerEventType.CookBoy3IntegralUserCrossRank.getValue());
                eventTypeMap.put(eGamePlayerEventType.CookBoy3IntegralUserCrossRank.getValue(),tempEventMap);
                addEventRelationMap(activityInfo.getActivityId(),eventTypeMap);

                Map<Integer,Integer> tempRankMap = new ConcurrentHashMap<>();
                tempRankMap.put(RelationActivityMgr.EVENT_RANK_USER_TYPE, eGamePlayerEventType.CookBoy3IntegralUserCrossRank.getValue());
                addRankEventMap(activityInfo.getActivityId(),tempRankMap);
            }

        }

    }

    public static void reloadActivityData(){
        logger.info("reload CookBoyActivityMgr start");
        // 获取活动
        List<ActivityInfo> openActivityInfoList = CookBoyActivityMgr.getOpenActivityInfoList(eActivityType.CookingBoyActivity.getValue());
        addChildEvent(openActivityInfoList);
        if (openActivityInfoList.size() <= 0) {
            return;
        }
        List<Integer> activityIdList = new ArrayList<>();
        for(ActivityInfo activityInfo : openActivityInfoList){
            activityIdList.add(activityInfo.getActivityId());
            activityInfoMap.put(activityInfo.getActivityId(),activityInfo);
        }
        Map<Integer, Map<String, CookBoyConfig>> tempActivityCookBoyConfigMap = ActivityBussiness.getCookBoyActivityConfig(activityIdList);
        Map<Integer, Map<Integer, CookBoyFoodConfig>> tempActivityCookBoyFoodConfigMap = ActivityBussiness.getCookBoyActivityFoodConfig(activityIdList);
        Map<Integer, Map<Integer, CookBoy2DishConfig>> tempActivityCookBoy2DishConfigMap = ActivityBussiness.getCookBoy2ActivityDishConfig(activityIdList);

        for(int activityId : activityIdList){
            if(!tempActivityCookBoyConfigMap.containsKey(activityId)){
                tempActivityCookBoyConfigMap.put(activityId,new ConcurrentHashMap<>());
            }
            if(!tempActivityCookBoyFoodConfigMap.containsKey(activityId)){
                tempActivityCookBoyFoodConfigMap.put(activityId,new ConcurrentHashMap<>());
            }
            if(!tempActivityCookBoy2DishConfigMap.containsKey(activityId)){
                tempActivityCookBoy2DishConfigMap.put(activityId,new ConcurrentHashMap<>());
            }
        }
        cookBoyConfigMap = tempActivityCookBoyConfigMap;
        cookBoyFoodConfigMap = tempActivityCookBoyFoodConfigMap;
        cookBoyDishConfigMap = tempActivityCookBoy2DishConfigMap;
        for(ActivityInfo activityInfo : activityInfoMap.values()){
            //去加载对应逻辑类的方法
            CookBoyMgr.loadActivity(activityInfo.getActivityId());
        }
        RelationActivityRankMgr.reloadRank();
        playerReloadActivity();
        CookBoyMgr.reloadActivity();
        CookBoyMgr.removeActivity();
        getLogger().info("reload CookBoyActivityMgr end");
    }


    public static Map<String, CookBoyConfig> getActivityConfigMap(int activityId){
        return cookBoyConfigMap.get(activityId);
    }

    public static Map<Integer, CookBoyFoodConfig> getActivityFoodConfigMap(int activityId){
        return cookBoyFoodConfigMap.get(activityId);
    }

    public static Map<Integer, CookBoy2DishConfig> getActivityDishConfigMap(int activityId){
        return cookBoyDishConfigMap.get(activityId);
    }

    //是否可以直接登录就参加
    public static boolean isCookBoy2Able(int activityId){
        String strConfig = COOKBOY2_SWITCH;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_SWITCH")){
                strConfig = configMap.get("COOKBOY2_SWITCH").getValue();
            }
        }
        return Integer.valueOf(strConfig) == 0;
    }


    public static int getCookBoy2PickUpItemId(int activityId){
        String strConfig = COOKBOY2_PICK_UP_ITEMID;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_PICK_UP_ITEMID")){
                strConfig = configMap.get("COOKBOY2_PICK_UP_ITEMID").getValue();
            }
        }
        return Integer.valueOf(strConfig);
    }

    public static boolean isCookBoy3Able(int activityId){
        String strConfig = COOKBOY3_SWITCH;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY3_SWITCH")){
                strConfig = configMap.get("COOKBOY3_SWITCH").getValue();
            }
        }
        return Integer.valueOf(strConfig) == 0;
    }

    //是不是跑马灯品质
    public static boolean isHorseNoticeQuality(int activityId,int dishId){
        CookBoy2DishConfig cookBoy2DishConfig = getDishConfig(activityId,dishId);
        if(cookBoy2DishConfig == null){
            return false;
        }
        for(Integer quality : getHouseNoticeQuality(activityId)){
            if(quality == cookBoy2DishConfig.getQuality()){
                return true;
            }
        }
        return false;
    }

    public static CookBoy2DishConfig getDishConfig(int activityId,int dishId){
        if(cookBoyDishConfigMap.containsKey(activityId)){
            if(cookBoyDishConfigMap.get(activityId).containsKey(dishId)){
                return cookBoyDishConfigMap.get(activityId).get(dishId);
            }
        }
        return null;
    }

    public static List<Integer> getCookBoy2SpoonIdList(int activityId){
        List<Integer> spoonIdList = new ArrayList<>();
        String strConfig = COOKBOY2_TRY_DISH_CONFIG;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_TRY_DISH_CONFIG")){
                strConfig = configMap.get("COOKBOY2_TRY_DISH_CONFIG").getValue();
            }
        }
        List<String> infoList = StringUtils.stringToStringList(strConfig,"\\|");
        for(String info : infoList){
            List<String> itemList = StringUtils.stringToStringList(info,";");
            String consume = itemList.get(0);
            int itemId = StringUtils.stringToIntegerList(consume,"=").get(0);
            spoonIdList.add(itemId);
        }
        return spoonIdList;
    }

    public static CookBoy2Spoon getCookBoy2MinSpoon(int activityId){
        String strConfig = COOKBOY2_TRY_DISH_CONFIG;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_TRY_DISH_CONFIG")){
                strConfig = configMap.get("COOKBOY2_TRY_DISH_CONFIG").getValue();
            }
        }
        List<String> infoList = StringUtils.stringToStringList(strConfig,"\\|");
        //机器人默认第一个道具赴宴处理
        for(String info : infoList){
            List<String> itemList = StringUtils.stringToStringList(info,";");
            String consume = itemList.get(0);
            int itemId = StringUtils.stringToIntegerList(consume,"=").get(0);
            CookBoy2Spoon cookBoy2Spoon = new CookBoy2Spoon();
            cookBoy2Spoon.setItemId(itemId);
            cookBoy2Spoon.setJoinerIntegral(Long.valueOf(itemList.get(1)));
            cookBoy2Spoon.setUserIntegral(Long.valueOf(itemList.get(2)));
            cookBoy2Spoon.setConsume(consume);
            return cookBoy2Spoon;
        }
        return null;
    }

    public static List<Integer> getHouseNoticeQuality(int activityId){
        String strConfig = COOKBOY2_HORSE_RACE_LAMP_QUALITY;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_HORSE_RACE_LAMP_QUALITY")){
                strConfig = configMap.get("COOKBOY2_HORSE_RACE_LAMP_QUALITY").getValue();
            }
        }
        List<Integer> qualityList = StringUtils.stringToIntegerList(strConfig,";");
        return qualityList;
    }

    public static String getCookBoy2JoinerReward(int activityId,int spoonId){
        CookBoy2Spoon cookBoy2Spoon = getCookBoy2Spoon(activityId,spoonId);
        if(cookBoy2Spoon != null){
            return getCookBoy2IntegralItemId(activityId) + ""+ cookBoy2Spoon.getJoinerIntegral();
        }
        return "";
    }

    public static CookBoy2Spoon getCookBoy2Spoon(int activityId,int spoonId){
        String strConfig = COOKBOY2_TRY_DISH_CONFIG;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_TRY_DISH_CONFIG")){
                strConfig = configMap.get("COOKBOY2_TRY_DISH_CONFIG").getValue();
            }
        }
        List<String> infoList = StringUtils.stringToStringList(strConfig,"\\|");
        for(String info : infoList){
            List<String> itemList = StringUtils.stringToStringList(info,";");
            String consume = itemList.get(0);
            int itemId = StringUtils.stringToIntegerList(consume,"=").get(0);
            if(itemId == spoonId){
                CookBoy2Spoon cookBoy2Spoon = new CookBoy2Spoon();
                cookBoy2Spoon.setItemId(itemId);
                cookBoy2Spoon.setJoinerIntegral(Long.valueOf(itemList.get(1)));
                cookBoy2Spoon.setUserIntegral(Long.valueOf(itemList.get(2)));
                cookBoy2Spoon.setConsume(consume);
                return cookBoy2Spoon;
            }
        }
        return null;
    }

    public static CookBoy3OpenItem getCookBoy3OpenItem(int activityId, int itemId){
        String strConfig = COOKBOY3_BANQUET_OPEN_CONFIG;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY3_BANQUET_OPEN_CONFIG")){
                strConfig = configMap.get("COOKBOY3_BANQUET_OPEN_CONFIG").getValue();
            }
        }
        List<String> infoList = StringUtils.stringToStringList(strConfig,"\\|");
        int i = 1;
        for(String info : infoList){
            List<String> itemList = StringUtils.stringToStringList(info,";");
            String consume = itemList.get(0);
            int itemConfigId = StringUtils.stringToIntegerList(consume,"=").get(0);
            if(itemConfigId == itemId){
                CookBoy3OpenItem config = new CookBoy3OpenItem();
                config.setItemId(itemId);
                config.setEatNum(Integer.valueOf(itemList.get(1)));
                config.setMinute(Integer.valueOf(itemList.get(2)));
                config.setIntegral(Long.valueOf(itemList.get(3)));
                config.setConsume(consume);
                config.setPos(i);
                return config;
            }
            i++;
        }
        return null;
    }

    public static String getCookBoy3OpenJoinerReward(int activityId, int itemId){
        CookBoy3OpenItem cookBoy3OpenItem = getCookBoy3OpenItem(activityId,itemId);
        if(cookBoy3OpenItem == null){
            return "";
        }
        String strConfig = COOKBOY3_JOIN_BANQUET_REWARD;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY3_JOIN_BANQUET_REWARD")){
                strConfig = configMap.get("COOKBOY3_JOIN_BANQUET_REWARD").getValue();
            }
        }
        List<String> infoList = StringUtils.stringToStringList(strConfig,"\\|");
        return infoList.get(cookBoy3OpenItem.getPos()-1);
    }

    public static int getServeFoodTableSeat(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_PARTICPATE_COOKING_MAX_NUM")){
                return Integer.valueOf(configMap.get("COOKBOY_PARTICPATE_COOKING_MAX_NUM").getValue());
            }
        }
        return Integer.valueOf(COOKBOY_PARTICPATE_COOKING_MAX_NUM);
    }

    public static int getCookBoyHpItemId(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_RESTORE_ITEM_ID")){
                return Integer.valueOf(configMap.get("COOKBOY_RESTORE_ITEM_ID").getValue());
            }
        }
        return Integer.valueOf(COOKBOY_RESTORE_ITEM_ID);
    }

    public static int getCookBoyIntegralItemId(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_EXCHANGE_ITEM_ID")){
                return Integer.valueOf(configMap.get("COOKBOY_EXCHANGE_ITEM_ID").getValue());
            }
        }
        return Integer.valueOf(COOKBOY_EXCHANGE_ITEM_ID);
    }

    public static int getCookBoy2IntegralItemId(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_EXCHANGE_ITEM_ID")){
                return Integer.valueOf(configMap.get("COOKBOY2_EXCHANGE_ITEM_ID").getValue());
            }
        }
        return Integer.valueOf(COOKBOY2_EXCHANGE_ITEM_ID);
    }

    public static int getCookBoy3IntegralItemId(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY3_EXCHANGE_ITEM_ID")){
                return Integer.valueOf(configMap.get("COOKBOY3_EXCHANGE_ITEM_ID").getValue());
            }
        }
        return Integer.valueOf(COOKBOY3_EXCHANGE_ITEM_ID);
    }

    public static String getWorshipReward(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_WORSHIP_REWARDS")){
                return configMap.get("COOKBOY_WORSHIP_REWARDS").getValue();
            }
        }
        return COOKBOY_WORSHIP_REWARDS;
    }

    public static String getWorship2Reward(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_WORSHIP_REWARDS")){
                return configMap.get("COOKBOY2_WORSHIP_REWARDS").getValue();
            }
        }
        return COOKBOY2_WORSHIP_REWARDS;
    }

    public static String getWorship3Reward(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY3_WORSHIP_REWARDS")){
                return configMap.get("COOKBOY3_WORSHIP_REWARDS").getValue();
            }
        }
        return COOKBOY3_WORSHIP_REWARDS;
    }

    public static int getCookBoyHp(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_ENERGY_PARAM")){
                List<Integer> configList = StringUtils.stringToIntegerList(configMap.get("COOKBOY_ENERGY_PARAM").getValue(),";");
                return configList.get(0);
            }
        }
        List<Integer> configList = StringUtils.stringToIntegerList(COOKBOY_ENERGY_PARAM,";");
        return configList.get(0);
    }

    public static int getCookBoy2Hp(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_ENERGY_PARAM")){
                List<Integer> configList = StringUtils.stringToIntegerList(configMap.get("COOKBOY2_ENERGY_PARAM").getValue(),";");
                return configList.get(0);
            }
        }
        List<Integer> configList = StringUtils.stringToIntegerList(COOKBOY2_ENERGY_PARAM,";");
        return configList.get(0);
    }

    public static int getCookBoyMaxHp(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_ENERGY_PARAM")){
                List<Integer> configList = StringUtils.stringToIntegerList(configMap.get("COOKBOY_ENERGY_PARAM").getValue(),";");
                return configList.get(1);
            }
        }
        List<Integer> configList = StringUtils.stringToIntegerList(COOKBOY_INGREDIENTS_GENERATE_WEIGHT,";");
        return configList.get(1);
    }

    public static int getCookBoy2MaxHp(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_ENERGY_PARAM")){
                List<Integer> configList = StringUtils.stringToIntegerList(configMap.get("COOKBOY2_ENERGY_PARAM").getValue(),";");
                return configList.get(1);
            }
        }
        List<Integer> configList = StringUtils.stringToIntegerList(COOKBOY2_ENERGY_PARAM,";");
        return configList.get(1);
    }

    //获取自然恢复切菜体力的时间
    public static int getCookBoyRecoveryTime(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_ENERGY_CD_TIME")){
                return Integer.valueOf(configMap.get("COOKBOY_ENERGY_CD_TIME").getValue());
            }
        }
        return Integer.valueOf(COOKBOY_ENERGY_CD_TIME);
    }

    public static int getCookBoy2RecoveryTime(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_ENERGY_CD_TIME")){
                return Integer.valueOf(configMap.get("COOKBOY2_ENERGY_CD_TIME").getValue());
            }
        }
        return Integer.valueOf(COOKBOY2_ENERGY_CD_TIME);
    }


    public static Map<Integer,Integer> getMakeFoodWeightMap(int activityId){
        Map<Integer,Integer> map = new ConcurrentHashMap<>();
        List<Integer> configList = null;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_INGREDIENTS_GENERATE_WEIGHT")){
                configList = StringUtils.stringToIntegerList(configMap.get("COOKBOY_INGREDIENTS_GENERATE_WEIGHT").getValue(),"\\|");
            }
        }
        if(configList == null){
            configList = StringUtils.stringToIntegerList(COOKBOY_INGREDIENTS_GENERATE_WEIGHT,"\\|");
        }
        for(int i = 1;i <= configList.size(); i++){
            map.put(i,configList.get(i-1));
        }
        return map;
    }

    //获取各个等级的菜的分数
    public static Map<Integer,Integer> getMakeFoodScoreMap(int activityId){
        Map<Integer,Integer> map = new ConcurrentHashMap<>();
        List<Integer> configList = null;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_INGREDIENTS_GENERATE_SCORE")){
                configList = StringUtils.stringToIntegerList(configMap.get("COOKBOY_INGREDIENTS_GENERATE_SCORE").getValue(),"\\|");
            }
        }
        if(configList == null){
            configList = StringUtils.stringToIntegerList(COOKBOY_INGREDIENTS_GENERATE_SCORE,"\\|");
        }
        for(int i = 1;i <= configList.size(); i++){
            map.put(i,configList.get(i-1));
        }
        return map;
    }

    //切菜时候产生的随机等级菜
    public static int randomOneFoodLevel(int activityId){
        int randomLevel = 0;
        Map<Integer,Integer> weightMap = getMakeFoodWeightMap(activityId);
        int totalWeight = 0;
        for (Integer level : weightMap.keySet()) {
            int weight = weightMap.get(level);
            totalWeight += weight;
        }
        int randomNum = randomHelper.next(0, totalWeight);
        for (Integer level : weightMap.keySet()) {
            int value = weightMap.get(level);
            if (randomNum < value) {
                randomLevel = level;
                break;
            }
            randomNum -= value;
        }
        return randomLevel;
    }

    //挑菜
    public static CookBoy2DishConfig randomPickDishId(int activityId){
        CookBoy2DishConfig randomDish = null;
        Map<Integer, CookBoy2DishConfig> dishMap = getActivityDishConfigMap(activityId);
        int totalWeight = 0;
        for (CookBoy2DishConfig cookBoy2DishConfig : dishMap.values()) {
            int weight = cookBoy2DishConfig.getWeight();
            totalWeight += weight;
        }
        int randomNum = randomHelper.next(0, totalWeight);
        for (CookBoy2DishConfig cookBoy2DishConfig : dishMap.values()) {
            int value = cookBoy2DishConfig.getWeight();
            if (randomNum < value) {
                randomDish = cookBoy2DishConfig;
                break;
            }
            randomNum -= value;
        }
        return randomDish;
    }

    public static String randomPickReward(int activityId){
        String rewardStr = COOKBOY2_PICK_DISH_REWARDS;
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_PICK_DISH_REWARDS")){
                rewardStr =  configMap.get("COOKBOY2_PICK_DISH_REWARDS").getValue();
            }
        }
        List<String> rewardInfoList = StringUtils.stringToStringList(rewardStr,"\\|");
        Map<String,Integer> weightRewardMap = new ConcurrentHashMap<>();
        for(String rewardInfo : rewardInfoList){
            List<String> rewardWeight = StringUtils.stringToStringList(rewardInfo,";");
            weightRewardMap.put(rewardWeight.get(0),Integer.valueOf(rewardWeight.get(1)));
        }
        int totalWeight = 0;
        for (Integer weight : weightRewardMap.values()) {
            totalWeight += weight;
        }
        int randomNum = randomHelper.next(0, totalWeight);
        for (String reward : weightRewardMap.keySet()) {
            int value = weightRewardMap.get(reward);
            if (randomNum < value) {
                return reward;
            }
            randomNum -= value;
        }
        return "";
    }



    public static List<String> randomPickReward(int activityId,int times){
        List<String> rewardList = new ArrayList<>();
        for(int i = times;i > 0;i--){
            rewardList.add(randomPickReward(activityId));
        }
        return rewardList;
    }

    //获取连击加成后的加成千分比
    public static int getMergeFoodCombe(int activityId,int lv,int count){
        Map<Integer,Integer> rangeMap = new ConcurrentHashMap<>();//范围，对应的连击加成
        Map<Integer,Map<Integer,Integer>> combeMap = new ConcurrentHashMap<>();//等级，序号,连击千分比
        String rangeInfoStr = null;
        String levelInfoStr = null;//等级，对应的连击加成
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_INGREDIENTS_COMB_LIST")){
                rangeInfoStr = configMap.get("COOKBOY_INGREDIENTS_COMB_LIST").getValue();
            }
            if(configMap.containsKey("COOKBOY_INGREDIENTS_COMB_EFFECT_LIST")){
                levelInfoStr = configMap.get("COOKBOY_INGREDIENTS_COMB_EFFECT_LIST").getValue();
            }
        }
        if(rangeInfoStr == null){
            rangeInfoStr = COOKBOY_INGREDIENTS_COMB_LIST;
        }
        if(levelInfoStr == null){
            levelInfoStr = COOKBOY_INGREDIENTS_COMB_EFFECT_LIST;
        }
        List<Integer> rangeList = StringUtils.stringToIntegerList(rangeInfoStr,"\\|");
        for(int level = 1; level <= rangeList.size(); level++){
            rangeMap.put(level,rangeList.get(level-1));
        }
        List<String> levelInfoList = StringUtils.stringToStringList(levelInfoStr,"\\|");
        for(int level = 1; level <= GameConfig.COOK_BOY_FOOD_MAX_LEVEL; level++){
            if(!combeMap.containsKey(level)){
                combeMap.put(level,new ConcurrentHashMap<>());
            }
            List<Integer> combeValueList = StringUtils.stringToIntegerList(levelInfoList.get(level-1),";");
            for(int index = 1; index <= rangeList.size(); index++){
                combeMap.get(level).put(index,combeValueList.get(index-1));
            }
        }
        int targetCombeIndex = 0;
        for (int combeIndex : rangeMap.keySet()){
            if(count >= rangeMap.get(combeIndex)){
                if(targetCombeIndex < combeIndex){
                    targetCombeIndex = combeIndex;
                }
            }
        }
        return combeMap.get(lv).getOrDefault(targetCombeIndex,0);
    }

    private static CookBoyFoodConfig getCookBoyFoodConfig(int activityId,int finishFoodId){
        for(CookBoyFoodConfig cookBoyFoodConfig : cookBoyFoodConfigMap.get(activityId).values()){
            if(cookBoyFoodConfig.getCookingId() == finishFoodId){
                return cookBoyFoodConfig;
            }
        }
        return null;
    }

    //获取当前正在生成的成品菜id
    public static int getMakeFinishFoodId(int activityId,int finishFoodId,Map<Integer,CookBoyFinishFood> cookBoyFinishFoodList){
        CookBoyFoodConfig cookBoyFoodConfig = getCookBoyFoodConfig(activityId,finishFoodId);
        int count = 0;
        for(CookBoyFinishFood cookBoyFinishFood : cookBoyFinishFoodList.values()){
            if(cookBoyFinishFood.getFoodId() == finishFoodId){
                count++;
            }
        }
        if(cookBoyFoodConfig == null){
            return finishFoodId;
        }
        if(count >= cookBoyFoodConfig.getUnlockCondition() && 0 != cookBoyFoodConfig.getUnlockCondition()){
            return cookBoyFoodConfigMap.get(activityId).get(cookBoyFoodConfig.getCookingOrder() + 1).getCookingId();
        }
        return finishFoodId;
    }

    //获取初始默认合成出来的最终菜
    public static int getDefaultCookingId(int activityId){
        return cookBoyFoodConfigMap.get(activityId).get(1).getCookingId();
    }

    //最终菜分数加成
    public static int getCookBoyFinishFoodAddScore(int activityId,int finishFoodId){
        CookBoyFoodConfig cookBoyFoodConfig = getCookBoyFoodConfig(activityId,finishFoodId);
        if(cookBoyFoodConfig == null){
            return 0;
        }
        return cookBoyFoodConfig.getAddScore();
    }

    private static void playerReloadActivity() {
        List<GamePlayer> playerList = GamePlayerMgr.getCopyPlayerList();
        playerList.forEach(action -> {
            action.getModule(CookBoyActivityModule.class).addNewActivity();
            action.getModule(CookBoyActivityModule.class).syncActivity();
            action.getModule(CookBoyModule.class).loadData();
            action.getModule(CookBoyModule.class).loginSendMsg();
        });
    }

    public static int getServeFoodStartHour(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_SERVE_FOOD_DAY_START")){
                return Integer.valueOf(configMap.get("COOKBOY_SERVE_FOOD_DAY_START").getValue());
            }
        }
        return Integer.valueOf(COOKBOY_SERVE_FOOD_DAY_START);
    }

    public static int getServeDishStartHour(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_SERVE_FOOD_DAY_START")){
                return Integer.valueOf(configMap.get("COOKBOY2_SERVE_FOOD_DAY_START").getValue());
            }
        }
        return Integer.valueOf(COOKBOY2_SERVE_FOOD_DAY_START);
    }

    public static int getServeBanquetStartHour(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY3_SERVE_FOOD_DAY_START")){
                return Integer.valueOf(configMap.get("COOKBOY3_SERVE_FOOD_DAY_START").getValue());
            }
        }
        return Integer.valueOf(COOKBOY3_SERVE_FOOD_DAY_START);
    }

    public static int getServeFoodEndHour(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY_SERVE_FOOD_DAY_END")){
                return Integer.valueOf(configMap.get("COOKBOY_SERVE_FOOD_DAY_END").getValue());
            }
        }
        return Integer.valueOf(COOKBOY_SERVE_FOOD_DAY_END);
    }

    public static int getServeDishEndHour(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY2_SERVE_FOOD_DAY_END")){
                return Integer.valueOf(configMap.get("COOKBOY2_SERVE_FOOD_DAY_END").getValue());
            }
        }
        return Integer.valueOf(COOKBOY2_SERVE_FOOD_DAY_END);
    }

    public static int getServeBanquetEndHour(int activityId){
        if(cookBoyConfigMap.containsKey(activityId)){
            Map<String,CookBoyConfig> configMap = cookBoyConfigMap.get(activityId);
            if(configMap.containsKey("COOKBOY3_SERVE_FOOD_DAY_END")){
                return Integer.valueOf(configMap.get("COOKBOY3_SERVE_FOOD_DAY_END").getValue());
            }
        }
        return Integer.valueOf(COOKBOY3_SERVE_FOOD_DAY_END);
    }

    public static boolean isActivityMatchTime(ActivityInfo activityInfo){
        if(null == activityInfo){
            return false;
        }
        long nowTime = System.currentTimeMillis() / 1000;
        if(nowTime < activityInfo.getBeginTime() && nowTime > activityInfo.getEndTime()){
            return false;
        }
        int nowHour = DateHelper.getHours();
        if(activityInfo.getChildType() == eActivityCookBoyType.Process1.getChildType()){
            //早上10点到晚上10点才会进行
            if(nowHour < getServeFoodStartHour(activityInfo.getActivityId()) || nowHour >= getServeFoodEndHour(activityInfo.getActivityId())){
                return false;
            }
        }else if(activityInfo.getChildType() == eActivityCookBoyType.Process2.getChildType()){
            //早上10点到晚上10点才会进行
            /*if(nowHour < getServeDishStartHour(activityInfo.getActivityId()) || nowHour >= getServeDishEndHour(activityInfo.getActivityId())){
                return false;
            }*/
        }else if(activityInfo.getChildType() == eActivityCookBoyType.Process3.getChildType()){
            //早上10点到晚上10点才会进行
            /*if(nowHour < getServeBanquetStartHour(activityInfo.getActivityId()) || nowHour >= getServeBanquetEndHour(activityInfo.getActivityId())){
                return false;
            }*/
        }

        return true;
    }

    public static CookBoyActivityProto.CookBoyActivityDetailMsg.Builder getCookBoyActivityDetailMsg(Map<Integer,Map<Integer, RelationActivityData>> activityDataMap, String language){
        return CookBoyActivityPb.parseCookBoyActivityDetailMsg(activityDataMap, getOpenActivityInfoList(eActivityType.CookingBoyActivity.getValue()), activityConditionInfoMap, activityMallInfoMap, language);
    }
}
